
<div class="span12">
    <div class="box box-color box-bordered">
        <div class="box-title">
            <h3>
                <i class="icon-table"></i>
                Promociones
            </h3>
            <div class="actions">
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_ORDER'))) { ?>
                    <a href="#mdlOrder" role="button" class="btn" data-toggle="modal"><i class="icon-table"></i></a>
                <?php } ?>
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_FILTER'))) { ?>
                    <!--a href="#mdlFilter" role="button" class="btn" data-toggle="modal"><i class="icon-search"></i></a-->
                <?php } ?>
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_EXCEL'))) { ?>
                    <a href="<?php echo url_for('/promotions/excelPromotions');?>?id=<?php echo $_GET['id'];?>" role="button" class="btn" ><i class="icon-download-alt"></i></a>
                <?php } ?>
              
            </div>
        </div>
        <div class="box-content nopadding">
            
            <?php //echo $userOrderCount;die();
            
            if($userOrderCount !=0){
            ?>
            <table class="table table-bordered dataTable dataTable-scroll-x">
                <thead>
                    <tr>
                        <?php 
                        foreach ($userTableOrder as $value) {?>
                            
                       
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==53 && $value['UserTableOrder'][0]['visible']==1){?><th>Cadena</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==54 && $value['UserTableOrder'][0]['visible']==1){?><th>Producto</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==55 && $value['UserTableOrder'][0]['visible']==1){?><th>Precio Promoción</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==56 && $value['UserTableOrder'][0]['visible']==1){?><th>Formato Promoción</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==57 && $value['UserTableOrder'][0]['visible']==1){?><th>Descuento</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==58 && $value['UserTableOrder'][0]['visible']==1){?><th>Código</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==59 && $value['UserTableOrder'][0]['visible']==1){?><th>Categoría</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==60 && $value['UserTableOrder'][0]['visible']==1){?><th>Marca</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==61 && $value['UserTableOrder'][0]['visible']==1){?><th>Únidades</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==62 && $value['UserTableOrder'][0]['visible']==1){?><th>Catalogo</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==63 && $value['UserTableOrder'][0]['visible']==1){?><th>Precio Sugerido</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==64 && $value['UserTableOrder'][0]['visible']==1){?><th>Fecha Inicio</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==65 && $value['UserTableOrder'][0]['visible']==1){?><th>Fecha Término</th><?php }?>
                        
                        
                        <?php }?>
                    </tr>
                </thead>
                <tbody>
                    
                        <?php
                        $dataArray = array();
                        $i = 0;
                        foreach ($promotions as $value) {

                            $dataArray[$i][]['cadena'] = $value['name'];
                            $dataArray[$i][]['producto'] = $value['name'];
                            $dataArray[$i][]['pPromocion'] = $value['name'];
                            $dataArray[$i][]['fPromocion'] = $value['name'];
                            $dataArray[$i][]['descuento'] = $value['name'];
                            $dataArray[$i][]['codigo'] = $value['name'];
                            $dataArray[$i][]['categoria'] = $value['name'];
                            $dataArray[$i][]['marca'] = $value['name'];
                            $dataArray[$i][]['unidades'] = $value['name'];
                            $dataArray[$i][]['catalogo'] = $value['name'];
                            $dataArray[$i][]['psugerido'] = $value['name'];
                            $dataArray[$i][]['fInicio'] = $value['name'];
                            $dataArray[$i][]['fTermino'] = $value['name'];
                            $i++;
                        }


                        for ($x = 0; $x < $i; $x++) {
                            ?>
                            <tr>

                                        <?php foreach ($userTableOrder as $value) { ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 53 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][0]['cadena']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 54 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][1]['producto']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 55 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][2]['pPromocion']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 56 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][3]['fPromocion']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 57 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][4]['descuento']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 58 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][5]['codigo']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 59 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][6]['categoria']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 60 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][7]['marca']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 61 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][8]['unidades']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 62 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][9]['catalogo']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 63 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][10]['pSugerido']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 64 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][11]['fInicio']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 65 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][12]['fTermino']; ?></td><?php } ?>
                                        <?php }
                                        ?>
                            </tr>
                            <?php
                        }
                        ?>

                </tbody>
            </table>
            
            <?php }else{ ?>  
            
            <table class="table table-bordered dataTable dataTable-scroll-x">
                <thead>
                    <tr>
                        <th>Cadena</th>
                        <th>Producto</th>
                        <th>Precio Promoción</th>
                        <th>Formato Promoción</th>
                        <th>Descuento</th>
                        <th>Código</th>
                        <th>Categoría</th>
                        <th>Marca</th>
                        <th>Únidades</th>
                        <th>Catalogo</th>
                        <th>Precio Sugerido</th>
                        <th>Fecha Inicio</th>
                        <th>Fecha Término</th>
                    </tr>
                </thead>
                <tbody>
                        
                    <?php foreach ($promotions as $value) { ?>

                        <tr>
                            <td><?php //echo $value['name'];?></td>
                            <td><?php echo $value['Products']['name'];?></td>
                            <td><?php echo $value['price_promotion'];?></td>
                            <td><?php echo $value['ProductsFormats']['name'];?></td>
                            <td><?php echo $value['discount'];?></td>
                            <td><?php echo $value['code_customer'];?></td>
                            <td><?php echo $value['CategoryProduct']['name'];?></td>
                            <td><?php echo $value['Brands']['name'];?></td>
                            <td><?php echo $value['units'];?></td>
                            <td><?php echo $value['catalog'];?></td>
                            <td><?php echo $value['price_suggested'];?></td>
                            <td><?php echo $value['promotion_date_start'];?></td>
                            <td><?php echo $value['promotion_date_end'];?></td>
                        </tr>
                    <?php } ?>

                </tbody>
            </table>
            
            
            <?php }?>
        </div>
    </div>
</div>